<template>
<d2-container>
<template slot="header">
  <h2>基本信息</h2>
</template>
<!-- 按钮 -->
<template >
<el-form ref="form" :model="form" label-width="80px" style="margin: 0 auto;width: 40%;">
<el-form-item label="考核类型" style="width: 55%;">
<el-select v-model="assessDetail.assessType" placeholder="日考核" >
<el-option
v-for="item in assessTypeList"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="考核部门" style="width: 55%;">
<el-select v-model="assessDetail.deptId" placeholder="请选择" >
<el-option  @click.native="getAssessed(assessDetail.deptId)"
v-for="item in deptlist"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="制度来源" style="width: 55%;">
<el-select v-model="assessDetail.sourceSystem" placeholder="请选择">
<el-option
  v-for="item in options"
  :key="item.id"
  :label="item.clauseContent"
  :value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="被考核人" style="width: 55%;" >
<el-select v-model="assessDetail.uid" placeholder="请选择" >
<el-option
v-for="item in assessedlist"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="考核人" style="width: 55%;">
<el-select v-model="assessDetail.assessPerson"  placeholder="请选择" >
<el-option
v-for="item in userlist"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="创建时间" disable style="width: 55%;">
<el-date-picker
  v-model="assessDetail.createTime"
  type="datetime"
  placeholder="当前时间">
</el-date-picker>
</el-form-item>
<el-form-item label="考核日期" style="width: 55%;">
<el-date-picker
v-model="assessDetail.assessTime"
type="datetime"
placeholder="考核时间">
</el-date-picker>
</el-form-item>
<el-form-item label="是否审核">
<el-radio v-model="assessDetail.check" label="0">否</el-radio>
<el-radio v-model="assessDetail.check" label="1">是</el-radio>
</el-form-item>
<el-form-item label="考核内容" >
<el-select v-model="assessDetail.projectIdList" multiple placeholder="请选择">
<el-option
v-for="item in projectlist"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="加扣类型">
<el-radio v-model="form.radio" label="1">加奖</el-radio>
<el-radio v-model="form.radio" label="2">扣奖</el-radio>
</el-form-item>
<el-form-item label="下发金额">
<el-input style="width: 20%;" v-model="assessDetail.bonus"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="addDailyAssess()">立即创建</el-button>
<el-button>取消</el-button>
</el-form-item>
</el-form>
</template>
</d2-container>
</template>
<style>
    .pagecomponents {
        position: absolute;
        left: 50%;
        top:50%;
        transform: translate(-50%,-50%);
    }

</style>
<script>
export default {
  data () {
    return {
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 5,
        total: 10

      },
      // 查询到的所有部门数组
      deptlist: [],
      // 制度来源
      options: [],
      // 考核人来源
      assessedlist: [],
      projectlist: [],
      // 所有用户
      userlist: [],
      // 考核类型
      assessTypeList: [{
        value: '日考核',
        label: '日考核'
      }],
      userPageObj: {
        currentPage: '1',
        limit: '10',
        data: {}
      },
      // 日考核详情新增对象
      assessDetail: {
        id: 0,
        deptName: '',
        deptId: null,
        assessType: '',
        sourceSystem: '',
        uid: '',
        assessPerson: '',
        assessPersonList: [],
        projectIdList: [],
        projectId: '',
        creator: 0,
        createTime: null,
        assessTime: null,
        check: '0',
        checkPersonId: 0,
        content: '',
        bonus: 0,
        updated: 0,
        detail: [],
        updateTime: null
      },
      multipleSelection: [],
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '1',
        desc: '',
        radio: '1'
      }

    }
  },
  // 注册分页组件
  components: {
  },
  // 加载页面就执行的方法
  created () {
    this.getdept()
    this.getClause()
    this.getAllUser()
    this.getAllProject()
  },
  // 只有调用才执行的方法
  methods: {
    // 查询所有部门
    getdept () {
      this.$request({
        url: 'dept/findAllDept',
        method: 'post'
      }).then((res) => {
        this.deptlist = res
        console.log(res)
      })
    },
    // 获取制度来源列表
    getClause () {
      this.$request({
        url: 'dayAssessClause/findClause',
        method: 'post'
      }).then((res) => {
        this.options = res
        console.log(res)
      })
    },
    // 获取被考核人
    getAssessed (did) {
      this.$request({
        url: 'user/findAllByDept',
        method: 'post',
        data: did
      }).then((res) => {
        this.assessedlist = res
        console.log(res)
      })
    },
    // 获取考核人
    getAllUser () {
      this.$request({
        url: 'user/findAll',
        method: 'post',
        data: this.userPageObj
      }).then((res) => {
        this.userlist = res.list
        console.log('res', res)
      })
    },
    // 获取考核项
    getAllProject () {
      this.$request({
        url: 'dayAssessProject/findAllProject',
        method: 'post'
      }).then((res) => {
        this.projectlist = res
      })
    },
    // 新增日考核项目
    addDailyAssess () {
      this.$request({
        url: 'dailyAssess/insert',
        method: 'post',
        data: this.assessDetail
      }).then((res) => {
        this.$message({
          type: 'success',
          message: '成功添加一条日考核!'
        })
      })
    },
    onSubmit () {
      console.log('submit!')
    },
    toggleSelection (rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    // 分页插件事件
    callFather (parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search () {
      this.getdata(this.formInline)
    }
  }
}
</script>
